package com.es.jdbc;


import oracle.jdbc.driver.OracleDriver;

import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 测试注册驱动的方式
 */
public class TestDriverReg {

    public static void main(String[] args) {
        //1.注册mysql驱动
        try {
            //加载一个名字叫xxx的类
            Class.forName("com.mysql.cj.jdbc.Driver");

            Class.forName("oracle.jdbc.driver.OracleDriver");

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        //
        DriverManager.drivers().forEach(System.out::println);
    }

    public static void main1(String[] args) {
        //注册mysql的驱动
        try {
            DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
        } catch (SQLException e) {
            e.printStackTrace();
        }

        //注册是oracle的驱动
        try {
            DriverManager.registerDriver(new OracleDriver());
        } catch (SQLException e) {
            e.printStackTrace();
        }

        //
        DriverManager.drivers().forEach(System.out::println);
    }
}
